#encoding=utf-8
import urllib2

url = 'http://www.baidu.com'

#IE9.0的User-Agent，包含在ua_header里
ua_header = {'User-Agent':"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;"}

#url连同headers一起构造Request请求，这个请求将附带.IE9.0浏览器的User-Agent
request = urllib2.Request(url, headers=ua_header)
#也可以通过调用Request.add_header()添加/修改一个特定的header
request.add_header("Connection","keep-alive")

#也可以通过调用Request.get_header()来查看header信息
request_header = request.get_header(header_name="Connection")
#print request_header
response = urllib2.urlopen(request)

#print response.code
html = response.read()

print html